<template>
	<!--POP画册、POP下单、道具下单-->
	<view class="page-content">
		<view class="page-body" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
			<!--封面-->
			<view class="body-box1">
				<image class="com-body-img" :src="objdata.img" mode="aspectFill"  @click.stop="look(objdata.img)"></image>
				<image class="sel-img" :src="$mAssetsPath.icon_replace" @click.stop="replace_img('0',objdata.id,'fengmian')"></image>
				<view class="com-body-box">
					<view class="box-name">{{objdata.title}}</view>
					<image @click.stop="edit_tit(objdata.title)" class="box-remark-r" :src="$mAssetsPath.icon_bianji3">
					</image>
				</view>
			</view>

			<!--流程-->
			<view class="body-box2" @click="tolinkflow">
				<view class="box-l" :style="{color:objdata.flowname ===''?'#999':'#333'}">
					{{objdata.flowname ===''?'流程：':objdata.flowname}}
				</view>
				<view class="icons icon-gengduo"></view>
			</view>

			<!--产品图片数据-->
			<template v-if="objdata.objlist && objdata.objlist.length > 0 ">
				<view class="body-box">
					<product-num-edit :obj="objdata.objlist" :list="list" :list2="list2" @delItem="delItem"
						@delItem2="delItem2" @delItem3="delItem3" @checks="checks" @edit_remark="edit_remark" @choose="choose" @delete_img="delete_img"
						@confirm="confirm_sel" @add_pro="add_pro" @add_pro2="add_pro2" @sel_mat="sel_mat" @replace_img="replace_img"
						@rednum2="rednum2" @replaceFormat="replaceFormat" @rednum1="rednum1" @addnum2="addnum2" @addnum1="addnum1" :pageType="pageType">
					</product-num-edit>
				</view>

				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</view>
		<view class="btn-box" v-if="objdata.objlist.length > 0">
			<button class="submit" @tap="confirm()">保存</button>
		</view>
		<w-popup :show="showtip" :type="type1" @change="change1">
			<view class="w-tip">
				<view class="w-con">
					<view class="w-con-txt" v-if="pageType==='pop'" @click="toPop">POP画册</view>
					<view class="w-con-txt" @click="photoAlbum">手机相册</view>
					<view class="w-con-cen" @click="cancel('tip')">取消</view>
				</view>
			</view>
		</w-popup>
		<w-popup :show="showtip2" :type="type1" @change="change1">
			<view class="w-tip3">
				<view class="w-con">
					<view class="w-con-txt" v-if="pageType==='pop'" @click="toPop2">POP画册</view>
					<view class="w-con-txt" @click="changPhoto">手机相册</view>
					<view class="w-con-cen" @click="cancel('tip2')">取消</view>
				</view>
			</view>
		</w-popup>
		<!--编辑框-->
		<w-popup :show="showinput" :type="type1" @change="change1">
			<view class="w-tip2">
				<view class="w-tit">{{popType==='1'?'备注':popType==='2'?'提示':'编辑'}}</view>
				<view class="w-con">
					<input class="txt-input" v-if="popType==='1' || popType==='3'" type="text" v-model="mark" placeholder="请输入备注"
						placeholder-style="color:#bbb;font-size:26rpx"></input>
					<view class="txt-row" v-else-if="popType==='2'">是否删除？</view>
				</view>
				<view class="w-but">
					<view class="w-but-txt" @click="cancel('tip')">取消</view>
					<view class="w-but-txt" @click="confirm2">确认</view>
				</view>
			</view>
		</w-popup>
	</view>
</template>

<script>
	import wSelSearch from '@/components/w-sel-logo/w-sel-search.vue'; //标题
	import loadMore from '@/components/uni-load-more/load-more.vue';
	import productNumEdit from '@/pages/components/product_num_edit.vue';
	import wPopup from '@/components/w-popup/w-popup2.vue';
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import {
		taskDataInfos, //获取任务详情
		getFlowLists, //获取流程
		getProductTextureLists, //材质列表
		getProductCodingLists, //pop列表
		saveTaskDatas, //保存
		editTasks, //编辑流程
		getOssUploadsParams

	} from '@/common/api.js';
	export default {
		components: {
			loadMore,
			productNumEdit,
			wSelSearch,
			wPopup
		},
		data() {
			return {
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				page_title: '',
				objdata: {
					id: 1,
					image: '/static/data-img/img.jpg',
					title: '任务名任务名任务名任务名',
					flowname: '',
					datalist: [],
					objlist: []
				},
				list: [],
				list2: [],
				poptype: 1, //弹窗类型
				system: {
					w: 0,
					h: 0,
					scale: 1,
					systemScale: 1,
				},
				sel_img_index: 0, //选择当前项
				sel_img_id: 0, //选择当前项
				sel_index: 0, //选择当前项
				sel_ind: 0, //选择当前项
				mark: '',
				showtip: false, //是否显示弹窗1
				showtip2: false, //是否显示弹窗1
				showinput: false,
				content1: '顶部弹 popup',
				type1: '', //弹窗显示方式
				params: {
					id: '',
					company_id: '',
				},
				params2: {
					company_id: '',
					top_id: '',
					type: ''
				},
				json: {
					task_id: 0,
					company_id: 0,
					task_data: []
				},
				sourceType: ['album', 'camera'],
				chooseNum: 9,
				imglist:[], //上传图片-传参-新增图片
				pageType:'',
				popType:'',
				isReplace: false,
				replaceIndex: {
					oneIndex: 0,
					twoIndex: 0,
					threeIndex: 0
				}
			}
		},
		computed: {
			...mapGetters(['companyInfo', 'userInfo']),
			img_width() {
				return (this.system.w - 42) / 3;
			}
		},
		onShow() {
			uni.getSystemInfo().then(res => {
				let system = res[1]
				this.system.scale = 667 / 375 //按照苹果留 375*667比例 其他型号手机等比例缩放 显示
				this.system.systemScale = system.windowWidth / 375 //按照苹果留 375*667比例 其他型号手机等比例缩放 显示
				this.system.w = system.windowWidth;
				this.system.h = system.windowHeight;
			})

		},
		onLoad(option) {
			console.log(222, option)
			this.params.company_id = this.companyInfo.id;
			this.params2.company_id = this.companyInfo.id;
			this.json.company_id = this.companyInfo.id;
			if (!!option.title) {
				this.page_title = option.title;
			}
			if (option.id) {
				this.params.id = option.id;
			}
			if(option.pageType){
				this.pageType = option.pageType;
				this.getdata();
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(123, e)
			if (e.index === 0) {
				if(this.pageType === 'pop'){
					this.content1 = 'center'
					this.type1 = 'bottom';
					this.showtip = !this.showtip;
				}else if(this.pageType === 'prop'){
					this.selImg()
				}
			}
		},
		methods: {
			changPhoto(index) {
				this.selImg(true).then(url => {
					this.objdata.objlist[this.sel_img_index]. url = url
					this.showtip2 = false
				})
			},
			replaceFormat(val, replaceIndex, type, iiii, id){
				this.isReplace = true
				this.replaceIndex = replaceIndex
				if(type == 1) {
					this.add_pro(iiii, replaceIndex.oneIndex, "0", type, true)
				} else if (type == 2) {
					this.add_pro(iiii, replaceIndex.twoIndex, id, type, true)
				} else if (type == 3) {
					this.add_pro2(iiii, replaceIndex.oneIndex, replaceIndex.twoIndex, id, type, true)
				}
			},
			//选择图片
			selImg(isReplace) {
				return new Promise(topReslove => {
					let _self = this;
					uni.chooseImage({
						count: this.chooseNum,
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: this.sourceType,
						success: (tempFilePaths) => {
							console.log('选择文件：', tempFilePaths)
							uni.showLoading({
								title: '上传中'
							});
							let uploadImgs = [];
							getOssUploadsParams().then(res => {
								if (res.code === 2000) {
									tempFilePaths.tempFilePaths.forEach((item, index) => {
										uploadImgs.push(new Promise((resolve, reject) => {
											let file_path = item;
											let filename = tempFilePaths.tempFiles[
												index];
											let suffix = "." + _self.getCaption(
												filename.path);
											let file_name = new Date().getTime() + Math
												.random().toString(
													36).substring(3, 20) + suffix
											console.log(333333, file_name, filename)
											//上传图片接口
											uni.uploadFile({
												url: res.data.host,
												filePath: file_path,
												fileType: 'image',
												name: 'file',
												formData: {
													name: file_path,
													'key': res.data.dir + file_name,
													'policy': res.data.policy,
													'OSSAccessKeyId': res.data.accessid,
													'success_action_status': '200',
													//让服务端返回200,不然，默认会返回204
													'signature': res.data.signature,
												},
												success: (res2) => {
													resolve(res2);
													let url = res.data.host + '/' + res.data.dir + file_name;
													let img_list = {
														url
													}
													if(isReplace) {
														topReslove(url)
													} else {
														_self.imglist.push(img_list)
													}

												},
												fail: (err) => {
													console.log(err);
													reject(err);
												},
												complete: () => {
													//uni.hideLoading();
												}
											});
										}))
										Promise.all(uploadImgs).then((results) => { //执行所有需请求的接口
													 if (index === (tempFilePaths.tempFilePaths.length - 1) && !isReplace) {
														if(this.pageType === 'pop'){
															uni.navigateTo({
																url: `/pages/picBook/createTask?task_id=${_self.params.id}&company_id=${_self.params.company_id}&type=2&pageType=pro&addType=popadd&selType=pop&img_list=${JSON.stringify(_self.imglist)}`
															})
														}else if(this.pageType === 'prop'){
															uni.navigateTo({
																url: `/pages/user/batch?task_id=${this.params.id}&pageType=prop&pageStatu=2&userType=system&selType=prop&imglist=${JSON.stringify(_self.imglist)}`
															})
														}
													 }
												uni.hideLoading();
											})
											.catch((res3, object) => {
												uni.hideLoading();
											});
									})
								}
							})
						}
					});
				})
			},
			edit_tit(title){
				this.popType = '3';
				this.showinput = true;
				this.content1 = 'center'
				this.type1 = 'center';
				this.mark = title;
			},
			//备注
			edit_remark(sel_img_index,id,item) {
				item.isPl = true
				this.$forceUpdate()
				// this.popType = '1';
				// this.showinput = true;
				// this.content1 = 'center'
				// this.type1 = 'center';
				// this.sel_img_id = id;
				// this.mark = '';
				// if (this.objdata.objlist && this.objdata.objlist.length > 0) {
				// 	this.objdata.objlist.forEach((item, index) => {
				// 		if(sel_img_index === index){
				// 			if (this.sel_img_id === item.id) {
				// 				this.mark = item.mark;
				// 			}
				// 		}
				// 	})
				// }
			},
			resdata2(item) {
				console.log(2222, item)
				this.objdata.flowname = item.title;
				this.objdata.flow_path_id = item.id;
			},
			resdata3(item){
				console.log(2222, item)
				if(this.objdata.objlist && this.objdata.objlist.length>0){
					this.objdata.objlist.forEach((ite,index)=>{
						if(this.sel_img_index === index){
							ite.product_album_data_id = item[0].id;
							ite.url = item[0].url;
							this.$forceUpdate() //二维数组，开启强制渲染
						}
					})
				}
			},
			resdata4(){
				this.getdata();
			},
			getdata() {
				taskDataInfos(this.params).then(res => {
					if (res.code === 2000) {
						this.objdata.title = res.data.title;
						this.objdata.img = res.data.img;
						this.objdata.objlist = res.data.dataList;
						this.objdata.id = res.data.id;
						this.objdata.type = res.data.type;
						this.objdata.flow_path_id = res.data.flow_path_id;
						let objlist = []
						if(res.data.dataList && res.data.dataList.length>0){
							res.data.dataList.forEach(item=>{
								let datalist = []
								this.$set(item, 'datalist', datalist)
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										this.$set(item2, 'count', 0);
										this.$set(item2, 'checked', true);
										if (item2.top_id === 0) {
											item.datalist.push(item2)
											let data = [];
											let texture = [];
											this.$set(item2, 'data', data)
											this.$set(item2, 'texture', texture)
											if(item.datalist && item.datalist.length>0){
												item.datalist.forEach(item3=>{
													if (item2.top_id === item3.product_coding_id) {
														item3.data.push(item2)
														if(item3.delete === 2){
															item3.texture.push(item2.texture_name)
														}
													}
												})
											}
										}
									})
								}
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										if(item.datalist && item.datalist.length>0){
											item.datalist.forEach(item3=>{
												if (item2.top_id === item3.product_coding_id) {
													item3.data.push(item2)
													if(item3.delete === 2){
														item3.texture.push(item2.texture_name)
													}
												}
												if(item3.data && item3.data.length>0){
													item3.data.forEach(item4=>{
														let data = [];
														this.$set(item4, 'data', data)
													})
												}
											})
										}
									})
								}
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										if(item.datalist && item.datalist.length>0){
											item.datalist.forEach(item3=>{
												if(item3.data && item3.data.length>0){
													item3.data.forEach(item4=>{
														if (item2.top_id === item4.product_coding_id) {
															item4.data.push(item2);
															item3.texture.push(item2.texture_name) //增加材质
															if(item4.data && item4.data.length>0){
																item4.data.forEach(item5=>{
																	if(item5.delete === 2){
																		item4.count = 1
																	}
																})
															}
														}
													})
												}
											})
										}
									})
								}
								objlist.push(item);
							})
						}
						this.objdata.objlist = objlist;
						console.log(44444, this.objdata.objlist)
						//流程
						getFlowLists({
							company_id: res.data.company_id
						}).then(res2 => {
							if (res2.code === 2000) {
								if (res2.data && res2.data.length > 0) {
									res2.data.forEach(item => {
										if (res.data.flow_path_id === item.id) {
											this.objdata.flowname = item.title;
										}
									})
								}
							}
						})
					}
				})
				//材质
				getProductTextureLists(this.params).then(res => {
					if (res.code === 2000) {
						this.list = res.data;
					}
				})
			},
			//跳转pop画册
			toPop() {
				uni.navigateTo({
					url: `/pages/picBook/picBookList?task_id=${this.params.id}&pageType=pro&pageStatu=2&userType=system&selType=pop`
				})
				this.showtip = false;
			},
			//跳转pop画册
			toPop2() {
				uni.navigateTo({
					url: `/pages/picBook/picBookList?task_id=${this.params.id}&pageType=pro&pageStatu=2&userType=system&selType=pop&selNum=one`
				})
				this.showtip2 = false;
			},
			//下弹窗
			photoAlbum() {
				this.selImg()
				this.showtip = false;
			},
			delete_img(sel_img_index,id){
				console.log(22,sel_img_index,id)
				this.popType = '2';
				this.showinput = true;
				this.content1 = 'center'
				this.type1 = 'center';
				this.sel_img_index = sel_img_index;
			},
			look(url){
				var imgArr = []
				 imgArr.push(url);
				//预览图片
				uni.previewImage({
					urls: imgArr,
					current: 0
				});
			},
			//修改图片
			replace_img(sel_img_index,id,imgType, isReplace) {
				return new Promise(topReslove => {
					console.log(11,sel_img_index,id,imgType,this.pageType)
					if((this.pageType ==='pop' && imgType === 'fengmian') || (this.pageType ==='prop' && imgType === 'fengmian') || (this.pageType ==='prop' && imgType === 'tuce')){
						uni.chooseImage({
							count: 1,
							sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
							sourceType: this.sourceType,
							success: (tempFilePaths) => {

								console.log('选择文件：', tempFilePaths)
								let _self = this;
								uni.showLoading({
									title: '上传中'
								});
								let uploadImgs = [];
								getOssUploadsParams().then(res => {
									if (res.code === 2000) {
										tempFilePaths.tempFilePaths.forEach((item, index) => {
											uploadImgs.push(new Promise((resolve, reject) => {
												let file_path = item;
												let filename = tempFilePaths.tempFiles[index];
												let suffix = "." + _self.getCaption(filename.path);
												let file_name = new Date().getTime() + Math.random().toString(36).substring(3, 20) + suffix
												console.log(333333, file_name, filename)
												//上传图片接口
												uni.uploadFile({
													url: res.data.host,
													filePath: file_path,
													fileType: 'image',
													name: 'file',
													formData: {
														name: file_path,
														'key': res.data.dir +file_name,
														'policy': res.data.policy,
														'OSSAccessKeyId': res.data.accessid,
														'success_action_status': '200',
														//让服务端返回200,不然，默认会返回204
														'signature': res.data.signature,
													},
													success: (res2) => {
														resolve(res2);
														let imgs = ''
														imgs = res.data.host + '/' + res.data.dir + file_name;
														if(isReplace) {
															topReslove(imgs)
														}else {
															if(imgType === 'fengmian'){
																_self.objdata.img = imgs
																console.log('上传的图片',_self.objdata.img)
															}else if(imgType === 'tuce'){
																if(_self.objdata.objlist && _self.objdata.objlist.length>0){
																	_self.objdata.objlist.forEach((item2,ind)=>{
																		if(sel_img_index === ind){
																			item2.url = imgs;
																		}
																	})
																}
															}
														}

														_self.$forceUpdate() //二维数组，开启强制渲染
														uni.showToast({
															title: '上传成功',
															icon: 'success',
															duration: 1000
														});
													},
													fail: (err) => {
														console.log(err);
														reject(err);
													},
													complete: () => {
														//uni.hideLoading();
													}
												});
											}))
											Promise.all(uploadImgs).then((results) => { //执行所有需请求的接口
													uni.hideLoading();
												})
												.catch((res3, object) => {
													uni.hideLoading();
												});

										})
									}
								})
							}
						});
					}else if(this.pageType ==='pop' && imgType === 'tuce'){
						this.content1 = 'center'
						this.type1 = 'bottom';
						this.showtip2 = true;
						this.sel_img_index = sel_img_index;
					}
				})
			},
			getCaption(obj) {
				var index = obj.lastIndexOf("\.");
				obj = obj.substring(index + 1, obj.length);
				return obj;
			},
			//跳转流程页面
			tolinkflow(id) {
				uni.navigateTo({
					url: `/pages/flow/flowlist`
				})
			},
			//增加0-级属性
			add_pro(iiii, index, top_id, poptype, isReplace = false) {
				this.isReplace = isReplace
				this.poptype = poptype;
				let _self = this;
				this.sel_img_index = iiii;
				this.sel_index = index;
				if(this.pageType === 'pop'){
					this.params2.type = 1;
				}else if(this.pageType === 'prop'){
					this.params2.type = 2;
				}
				if (this.poptype == '1') {
					this.params2.top_id = 0;
					getProductCodingLists(_self.params2).then(res => {
						if (res.code === 2000) {
							this.list2 = JSON.parse(JSON.stringify(res.data));
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									this.$set(item, 'count', 0)
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i1) => {
											if (iiii === i1) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.checked && item3.name === item.name && item3.delete === 2) {
															item.checked = true
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				} else if (this.poptype == '2') {
					this.params2.top_id = top_id;
					getProductCodingLists(this.params2).then(res2 => {
						if (res2.code === 2000) {
							this.list2 = JSON.parse(JSON.stringify(res2.data));
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									this.$set(item, 'count', 0)
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i2) => {
											if (iiii === i2) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.data && item3.data.length > 0) {
															item3.data.forEach((item4,i4) => {
																if (item4.checked && item4.name ===item.name  && item4.delete === 2) {
																	item.checked = true
																}
															})
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				}
			},
			add_pro2(iiii, index, ind, top_id, poptype) {
				console.log(555, index, ind, top_id, poptype)
				this.poptype = poptype;
				let _self = this;
				this.sel_img_index = iiii;
				this.sel_index = index;
				this.sel_ind = ind;
				this.params2.type = 1;
				if (this.poptype === '3') {
					this.params2.top_id = top_id;
					getProductCodingLists(_self.params2).then(res2 => {
						if (res2.code === 2000) {
							this.list2 = JSON.parse(JSON.stringify(res2.data));
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									this.$set(item, 'count', 0)
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i2) => {
											if (iiii === i2) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.data && item3.data.length > 0) {
															item3.data.forEach((item4,i4) => {
																if (item4.data && item4.data.length > 0) {
																	item4.data.forEach((item5,i5) => {
																		if (item5.checked && item5.name === item.name && item5.delete === 2) {
																			item.checked = true
																		}
																	})
																}
															})
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				}
			},
			//弹窗-下拉框选择
			checks(id, checked, isReplace) {
				this.isReplace = isReplace
				let _self = this;
				if (!checked) {
					if (this.poptype === '1') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item => {
								if (item.id === id) {
									item.checked = !checked;
									this.$set(item, 'product_coding_id', item.id);
									this.$set(item, 'delete', 2);
									delete item.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, ind) => {
											if (this.sel_img_index === ind) {
												//判断是否是替换还是新增
												if(this.isReplace) {
													console.log(this.objdata.objlist)
													item2.datalist[this.replaceIndex.oneIndex] = {
														...item,
														data: [],
														texture: [],
														id: item2.datalist[this.replaceIndex.oneIndex].id
													}
												} else {
													item2.datalist.push(item);
													console.log(999, item2.datalist)
													if (item2.datalist && item2.datalist.length > 0) {
														item2.datalist.forEach(item3 => {
															if (item3.data) {

															} else {
																let data = [];
																let texture = []
																this.$set(item3, 'data', data)
																this.$set(item3, 'texture', texture)
															}
														})
													}
												}

											}
										})
									}
								}
							})
						}
					} else if (this.poptype === '2') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item0 => {
								if (item0.id === id) {
									item0.checked = !checked;
									this.$set(item0, 'product_coding_id', item0.id);
									this.$set(item0, 'delete', 2);
									delete item0.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item, i) => {
											if (i === this.sel_img_index) {
												if (item.datalist && item.datalist.length > 0) {
													item.datalist.forEach((item2, ii) => {
														if (ii === this.sel_index) {
															if(this.isReplace) {
																item2.data[this.replaceIndex.twoIndex] = {
																	...item0,
																	data: [],
																	number: 0,
																	id: item.data[this.replaceIndex.twoIndex].id
																}
																this.$forceUpdate()
															} else {
																item2.data.push(item0)
																if(item2.delete === 2){
																	item2.texture.push(item0.texture_name);
																}

																if (item2.data && item2.data.length >0) {
																	item2.data.forEach((item3,iii) => {
																		let data = [];
																		if (item2.data.length -1 == iii) {
																			this.$set(item3,'data',data);
																			this.$set(item3,'number', 0);
																		}
																	})
																}
															}
														}
													})
												}
											}
										})
									}
								}
							})
						}
					} else if (this.poptype === '3') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item0 => {
								if (item0.id === id) {
									item0.checked = !checked;
									this.$set(item0, 'number', 0);
									this.$set(item0, 'product_coding_id', item0.id);
									this.$set(item0, 'delete', 2);
									delete item0.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item, i) => {
											if (i === this.sel_img_index) {

												if (item.datalist && item.datalist.length > 0) {
													item.datalist.forEach((item2, ii) => {
														if (ii === this.sel_index) {
															if (item2.data && item2.data.length >0) {
																item2.data.forEach((item3,iii) => {
																	if (iii === this.sel_ind) {
																		//判断是否替换
																		if(this.isReplace) {
																			item3.data[this.replaceIndex.threeIndex] = {
																				...item0,
																				id: item3.data[this.replaceIndex.threeIndex].id
																			}
																			item3.data[this.replaceIndex.texture] = item0.texture_name
																			if(item3.data && item3.data.length>0){
																				item3.data.forEach(item4=>{
																					if(item4.delete === 2){
																						item3.count = 1
																					}
																				})
																			}
																		} else {
																			item3.data.push(item0)
																			item2.texture.push(item0.texture_name);
																			if(item3.data && item3.data.length>0){
																				item3.data.forEach(item4=>{
																					if(item4.delete === 2){
																						item3.count = 1
																					}
																				})
																			}
																		}

																	}
																})
															}
														}
													})
												}
											}
										})
									}
								}
							})
						}
					}
				}
			},
			//材质选择
			choose(index) {
				if (this.list && this.list.length > 0) {
					this.list.forEach((item, ind) => {
						if (ind === index) {
							item.statu = !item.statu
						}
					})
				}
				console.log(11111, this.list)
			},
			//材质弹窗
			sel_mat() {
				if (this.list && this.list.length > 0) {
					this.list.forEach((item, ind) => {
						this.$set(item, 'statu', false);
					})
				}
			},
			//确认材质选择
			confirm_sel(list, index) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (this.sel_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										item2.texture = list;
									}
								})
							}
						}
					})
				}
			},
			//筛选项
			/* selnum(index) {
				console.log('点击图片', index)
				this.sel_img_index = index;
			}, */
			//删除一级
			delItem(sel_img_index, index, ind) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							let texture = []
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										/* let list = item2.data
										delete list[ind]
										item2.data = list.filter(Boolean) */
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (ind === iii) {
													item3.delete = 1;
												}
											})
										}
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												console.log(333,item3)
												if (item3.delete === 2) {
													texture.push(item3.texture_name);
												}
											})
										}
										item2.texture = texture
									}
								})
							}
						}
					})
				}

			},
			//删除0级
			delItem3(sel_img_index,index){
				console.log(1111,sel_img_index,index,this.objdata.objlist)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										item2.delete = 1;
										item2.texture = []
										if(item2.data && item2.data){
											item2.data.forEach(item3=>{
												item3.delete = 1
												if (item3.data && item3.data.length > 0) {
													item3.data.forEach((item4, iiii) => {
														item4.delete = 1;
													})
												}
											})
										}
									}

								})
							}
						}
					})
				}
			},
			//删除二级
			delItem2(sel_img_index, index, index2, index3) {
				console.log(1111, sel_img_index, index, index2, index3)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							let texture = [];
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if(item3.delete === 2){
													texture.push(item3.texture_name)
												}
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if (index3 === iiii) {
																item4.delete = 1;
															}
														})
													}
													let count = 0;
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if(item4.delete === 2){
																count = 1;
																texture.push(item4.texture_name)
															}
														})
													}
													item2.texture = texture
													item3.count = count;
													/* let list = item3.data
													delete list[index3]
													item3.data = list.filter(Boolean) */

												}
											})
										}
									}
								})
							}
						}
					})
				}
				console.log(11111, this.objdata.objlist)
			},
			rednum1(sel_img_index, index, index2) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.number > 0) {
														item3.number -= 1
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			addnum1(sel_img_index, index, index2) {
				console.log('一级增加', index, index2)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													item3.number += 1
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			rednum2(sel_img_index, index, index2, index3) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if (index3 === iiii) {
																if (item4.number > 0) {
																	item4.number -= 1
																}
															}
														})
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			addnum2(sel_img_index, index, index2, index3) {
				console.log('二级增加', index, index2, index3)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if (index3 === iiii) {
																item4.number += 1
															}
														})
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			//下一步
			confirm() {
				if(!this.objdata.title) {
					uni.showToast({
						title: '任务名不能为空',
						icon: 'none',
						duration: 2000
					})
					return
				}
				console.log(8888, this.objdata.objlist)
				let _self = this;
				this.json.task_id = this.objdata.id;
				let json = {
					company_id: this.json.company_id,
					title: this.objdata.title,
					type: this.objdata.type,
					img: this.objdata.img,
					flow_path_id: this.objdata.flow_path_id,
					id: this.objdata.id
				}

				editTasks(json).then(res => {
					if (res.code === 2000) {

					}
				})
				let task_datas = [];
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach(item => {
						if(this.pageType === 'pop'){
							let task_data = {
								id: '',
								image_name: '',
								product_album_data_id: '',
								mark: '',
								url: '',
								delete:'',
								data: []
							}
							task_data.id = item.id;
							task_data.image_name = item.image_name;
							task_data.url = item.url;
							task_data.product_album_data_id = item.product_album_data_id;
							task_data.mark = item.mark;
							task_data.delete = item.delete;
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									task_data.data.push(item2)
								})
							}
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											task_data.data.push(item3)
										})
									}
								})
							}
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											if (item3.data && item3.data.length > 0) {
												item3.data.forEach(item4 => {
													task_data.data.push(item4)
												})
											}
										})
									}
								})
							}
							task_datas.push(task_data)
						}else if(this.pageType === 'prop'){
							let task_data = {
								id: '',
								image_name: '',
								url: '',
								mark: '',
								delete:'',
								data: []
							}
							task_data.id = item.id;
							task_data.image_name = item.image_name;
							task_data.url = item.url;
							task_data.mark = item.mark;
							task_data.delete = item.delete;
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									task_data.data.push(item2)
								})
							}

							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											task_data.data.push(item3)
										})
									}
								})
							}
							task_datas.push(task_data)
						}
						console.log(999, task_datas)
					})
				}
				if (task_datas && task_datas.length > 0) {
					task_datas.forEach(item => {
						if (item.data && item.data.length > 0) {
							item.data.forEach(item2 => {
								delete item2.data;
								delete item2.create_time;
								delete item2.company_id;
								delete item2.delete_time;
								delete item2.name;
								delete item2.next_num;
								delete item2.product_texture_id;
								//delete item2.texture;
								delete item2.type;
								delete item2.update_time;

							})
						}
					})
				}
				this.json.task_data = task_datas
				saveTaskDatas(this.json).then(res => {
					if (res.code === 2000) {
						uni.showToast({
							title: '保存成功！',
							icon: 'none',
							duration: 2000
						})
						this.$util.prePage().resdata();
						setTimeout(() => {
							uni.navigateBack();
						}, 500)
					}
				})
			},
			//返回
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//重置筛选
			resetFilterData() {

			},
			//确认筛选
			setFilterData() {

			},
			loadmore() {

			},
			confirm2() {
				if(this.popType === '1'){ //编辑备注
					if (this.objdata.objlist && this.objdata.objlist.length > 0) {
						this.objdata.objlist.forEach((item, index) => {
							if (this.sel_img_id === item.id) {
								item.mark = this.mark;
							}
						})
					}
				}else if(this.popType === '2'){ //删除图册图片
					if(this.objdata.objlist && this.objdata.objlist.length>0){
						this.objdata.objlist.forEach((item,index)=>{
							if(this.sel_img_index === index){
								item.delete = 1
							}
						})
					}
				}else if(this.popType === '3'){ //编辑标题
					this.objdata.title = JSON.parse(JSON.stringify(this.mark))
				}
				this.showinput = false;
				console.log(666,this.objdata.objlist)

			},
			//底部弹窗
			change1(e) {
				if (!e.show) {
					this.showtip = false;
					this.showtip2 = false;
					this.showinput = false;
				}
			},
			//取消
			cancel(type) {
				this['show' + type] = false;
				this.showinput = false;
			},
		}
	}
</script>
<style></style>
<style lang="scss">
	/* 提示窗口 */
	.w-tip2 {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 70vw;
		border-radius: 10rpx;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		margin: 30rpx auto 0;

		.w-tit {
			font-size: 36rpx;
			font-weight: bold;
			color: $font-color-3;
			line-height: 60rpx;
			height: 60rpx;
			margin-top: 20rpx;
			text-align: center;
		}

		.w-but {
			display: flex;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-b3;
			height: 84rpx;
			line-height: 84rpx;

			.w-but-txt {
				flex: 1;
				text-align: center;
				border-right: 1rpx solid #f5f5f5;
			}

			.w-but-txt:last-of-type {
				border-right: none;
			}
		}

		.w-con {
			display: flex;
			text-align: center;
			font-weight: 400;
			padding: 30rpx 30rpx;
			border-bottom: 1rpx solid #f5f5f5;

			.txt-row {
				width: 100%;
				text-align: center;
				font-size: 28rpx;
				color: $font-color-9;
			}

			.txt-input {
				text-align: left;
				border: 1rpx solid #f5f5f5;
				padding: 0 20rpx;
				height: 60rpx;
				width: 100%;
			}
		}
	}

	/* 提示窗口 */
	.w-tip {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 100vw;
		min-height: 200rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		padding: 20rpx 0rpx;
		margin: 30rpx auto 0;

		.w-con {
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-3;
			text-align: center;

			.w-con-txt {
				border-bottom: 1rpx solid #f5f5f5;
			}

			.w-con-cen {
				color: #198FFF;
			}
		}
	}
	/* 提示窗口 */
	.w-tip3 {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 100vw;
		min-height: 100rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		padding: 20rpx 0rpx;
		margin: 30rpx auto 0;

		.w-con {
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-3;
			text-align: center;

			.w-con-txt {
				border-bottom: 1rpx solid #f5f5f5;
			}

			.w-con-cen {
				color: #198FFF;
			}
		}
	}

	.page-content {
		border-top: 1rpx solid #f5f5f5;
		width: 100vw;
		height: 100%;
		background: $uni-bg-color-grey;


		.btn-box {
			width: 100%;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			height: 90rpx;

			font-size: 36rpx;
			font-weight: bold;
			line-height: 90rpx;
			color: white;
			z-index: 10;

			.submit {
				text-align: center;
				color: white !important;
				flex: 2;
				border-radius: 0 !important;
				background-color: #198FFF;
			}
		}
		.page-body {
			width: 100vw;
			height: calc(100% - 90rpx);
			padding: 0rpx;

			.body-box {
				display: flex;
				flex-direction: column;
				background: $uni-bg-color;
				padding-bottom: 40rpx;

			}

			.body-box2 {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background: $uni-bg-color;
				padding: 30rpx;
				margin-bottom: 20rpx;

				.box-l {
					font-size: 32rpx;
					font-weight: 400;
				}
			}

			.body-box1 {
				display: flex;
				flex-direction: column;
				background: $uni-bg-color;
				padding: 30rpx 30rpx 0 30rpx;
				margin-bottom: 20rpx;
				position: relative;

				.sel-img {
					position: absolute;
					right: 60rpx;
					top: 60rpx;
					width: 60rpx;
					height: 60rpx;
				}

				.com-body-img {
					width: 100%;
					height: 388rpx;
					border-radius: 10rpx;
					margin-bottom: 30rpx;
					overflow: hidden;
				}

				.com-body-box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 26rpx;
					.box-name {
						font-size: 32rpx;
						font-weight: 400;
						color: $font-color-3;
					}
					.box-remark-r {
						margin-left: 30rpx;
						width: 30rpx;
						height: 30rpx;
					}
				}
			}
		}
	}
</style>
